Telegram Group & Telegram Channel
Перегрузка операторов

Сначала стоит напомнить, что методы, которые начинаются и заканчиваются двойными нижними подчеркиваниями, называются магическими.

Например, выше в классе Point мы определили __str__, который отвечает за то, как выводятся объекты класса на экран.

Для перегрузки оператора "+" нужно определить метод __add__. Он принимает два аргумента, которыми являются, соответственно, операнды в операции сложения.

Таким образом, когда разработчик пишет запись p1 + p2, интерпретатор воспринимает это в виде Point.__add__(p1, p2). Для всех операторов в языке, включая и логические, есть свои магические методы.

#классы



tg-me.com/python_academy/342
Create:
Last Update:

Перегрузка операторов

Сначала стоит напомнить, что методы, которые начинаются и заканчиваются двойными нижними подчеркиваниями, называются магическими.

Например, выше в классе Point мы определили __str__, который отвечает за то, как выводятся объекты класса на экран.

Для перегрузки оператора "+" нужно определить метод __add__. Он принимает два аргумента, которыми являются, соответственно, операнды в операции сложения.

Таким образом, когда разработчик пишет запись p1 + p2, интерпретатор воспринимает это в виде Point.__add__(p1, p2). Для всех операторов в языке, включая и логические, есть свои магические методы.

#классы

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/342

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

Telegram hopes to raise $1bn with a convertible bond private placement

The super secure UAE-based Telegram messenger service, developed by Russian-born software icon Pavel Durov, is looking to raise $1bn through a bond placement to a limited number of investors from Russia, Europe, Asia and the Middle East, the Kommersant daily reported citing unnamed sources on February 18, 2021.The issue reportedly comprises exchange bonds that could be converted into equity in the messaging service that is currently 100% owned by Durov and his brother Nikolai.Kommersant reports that the price of the conversion would be at a 10% discount to a potential IPO should it happen within five years.The minimum bond placement is said to be set at $50mn, but could be lowered to $10mn. Five-year bonds could carry an annual coupon of 7-8%.

Python Academy from cn


Telegram Python Academy
FROM USA